package cn.imvc.util;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

public class RequestBody {
	  public static String getPostRequestBody(HttpServletRequest req) {
	        if (req.getMethod().equals("POST")) {
	            StringBuilder sb = new StringBuilder();
	            try (BufferedReader br = req.getReader()) {
	                char[] charBuffer = new char[128];
	                int bytesRead;
	                while ((bytesRead = br.read(charBuffer)) != -1) {
	                    sb.append(charBuffer, 0, bytesRead);
	                }
	            } catch (IOException e) {
	            	e.printStackTrace();
	            }
	            return sb.toString();
	        }
	        return "";
	    }

}
